const { getdata, getproduct } = require('../service/shoper')
module.exports = {
    async getshopper(ctx, next) {
        const { address } = ctx.query
        const rudata = await getdata({ address, status: 1 })
        if (!rudata.length) {
            return ctx.body = {
                code: 400,
                msg: "没有商家"
            }
        }
        const random = Math.floor(Math.random() * rudata.length)
        console.log(rudata[random].id)
        const produrudata = await getproduct({ shoperid: rudata[random].id, status: 1 })
        return ctx.body = {
            code: 200,
            msg: "成功！",
            data: {
                shoper: rudata[random],
                product: produrudata
            }
        }
    },
    async shoperbyid(ctx, next) {
        const { id } = ctx.params
        const rudata = await getdata({ id })
        const produrudata = await getproduct({ shoperid: rudata[0].id, status: 1 })
        return ctx.body = {
            code: 200,
            msg: "成功！",
            data: {
                shoper: rudata[0],
                product: produrudata
            }
        }
    }
}